﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Bike.Repository;
using Telerik.WinControls.UI;

namespace Bike
{
    public class UIHelper
    {
        public static bool IsAccessoriesCategory(object cat)
        {
            if (cat == null) return false;
            if(cat.GetType() == typeof(Category)){
                return (cat as Category).Id == SessionManager.Configuration.AccessoriesCategoryId;
            }
            return Convert.ToInt32(cat) == SessionManager.Configuration.AccessoriesCategoryId;

        }
        public static void DisplayCategory(IEnumerable<Category> datasource, RadDropDownList ddl)
        {
            ddl.DataSource = datasource;
            ddl.DisplayMember = "Name";
            ddl.ValueMember = "Id";
            
            ddl.Invalidate();
        }

        public static void DisplayCustomer(IEnumerable<Customer> datasource, RadDropDownList ddl)
        {
            ddl.DataSource = datasource;
            ddl.DisplayMember = "Name";
            ddl.ValueMember = "Id";

            ddl.Invalidate();
        }

        public static void DisplayCategory(IEnumerable<Category> datasource, RadTreeView tree)
        {
            tree.Nodes.Clear();
            RadTreeNode root = new RadTreeNode()
            {
                Text = "CÔNG TY"
            };
            foreach (var item in datasource)
            {
                var node = new RadTreeNode() { Text = item.Name };
                foreach (var p in item.Products)
                {
                    node.Nodes.Add(new RadTreeNode() { Text = p.Name });
                }
                root.Nodes.Add(node);
            }
            tree.Nodes.Add(root);
        }
        public static void SetupDialog(RadForm form)
        {
            form.MaximizeBox = false;
            form.MinimizeBox = false;
            form.ShowInTaskbar = false;
            form.ControlBox = false;
            
        }

        internal static void DisplayProducts(IEnumerable<Product> datasource, RadDropDownList ddl)
        {
            ddl.DataSource = datasource;
            ddl.DisplayMember = "Name";
            ddl.ValueMember = "Id";

            ddl.Invalidate();
        }
    }
}
